package com.linkvin.ec.hcs.service.mdm.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.linkvin.ec.hcs.dao.mapper.mdm.RetailorMapper;
import com.linkvin.ec.hcs.dao.model.mdm.bo.RetailorBo;
import com.linkvin.ec.hcs.service.mdm.RetailorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
public class RetailorServiceImpl implements RetailorService{

    @Autowired
    private RetailorMapper retailorMapper;

    @Override
    public Page<RetailorBo> queryPageRetailor(Page<RetailorBo> page) {
        List<RetailorBo> listShopBo = retailorMapper.queryPageRetailor(page,buildCondition(page.getCondition()));
        page.setRecords(listShopBo);
        return page;
    }

    @Override
    public RetailorBo addRetailor(RetailorBo retailorBo) {
        return null;
    }

    @Override
    public RetailorBo updateRetailor(RetailorBo retailorBo) {
        return null;
    }

    @Override
    public int deleteRetailor(List<Integer> shopIds) {
        return 0;
    }

    private EntityWrapper<RetailorBo> buildCondition(Map<String,Object> condition){
        EntityWrapper<RetailorBo> ew = new EntityWrapper<>();
        if(!Objects.equals(condition,null)) {
            for (Map.Entry<String, Object> entry : condition.entrySet()) {
                if (entry.getKey().equals("name")) {
                    ew.like("full_name", entry.getValue().toString());
                }
            }
        }
        return ew;
    }
}
